include default.mk

OBJS    = startup.o main.o
OBJS   += muldiv.o lib0.o serial.o
OBJS   += kozos.o bitsearch.o dispatch.o syscall.o memory.o ipc.o ktimer.o
OBJS   += consdrv.o command.o put.o

TARGET  = kozos
LDSCRIPT = ld.scr
READELFOUT = readelf.out
DISASSOUT = disass.out
DEPEND = .depend

COMMONDIR = ../common

NETDIR = net
NETLIB = $(NETDIR)/net.a

CFLAGS += -I$(NETDIR)

.PHONY : all
all :
	$(MAKE) -C $(NETDIR) depend all
	$(MAKE) depend $(TARGET)

$(TARGET) : $(OBJS) $(LDSCRIPT) $(NETLIB)
	$(LD) $(OBJS) $(NETLIB) -o $(TARGET) -T $(LDSCRIPT)
	cp $(TARGET) $(TARGET).elf
	$(READELF) -a $(TARGET).elf > $(READELFOUT)
	$(OBJDUMP) -S $(TARGET).elf > $(DISASSOUT)
	$(STRIP) $(TARGET)

.PHONY : depend
depend :
	@$(CC) $(CFLAGS) -M *.[csS] > $(DEPEND)
-include $(DEPEND)

.PHONY : clean
clean :
	$(MAKE) -C $(NETDIR) clean
	rm -f $(OBJS) $(TARGET) $(TARGET).elf $(READELFOUT) $(DISASSOUT) $(DEPEND)
